package com.example.expresscabinet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.expresscabinet.dao.postageMapper;
import com.example.expresscabinet.model.cabinet;
import com.example.expresscabinet.model.postage;
import com.example.expresscabinet.service.IPostageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class postageServiceImpl extends ServiceImpl<postageMapper, postage> implements IPostageService {

    @Resource
    postageMapper postageMapper;

    //查询邮费
    @Override
    public int queryPostage(String start,String end,String company){
        QueryWrapper<postage> wrapper=new QueryWrapper<>();
        wrapper.eq("fromWhere",start).eq("toWhere",end).eq("company",company);
        postage post=postageMapper.selectOne(wrapper);
        int res=0;
        if(post!=null){
            res=post.getCost();
        }
        if(post==null){
            QueryWrapper<postage> wrapper1=new QueryWrapper<>();
            wrapper1.eq("toWhere",start).eq("fromWhere",end).eq("company",company);
            postage post1=postageMapper.selectOne(wrapper1);
            if(post1!=null){
                res=post1.getCost();
            }
        }

        return res;
    };
}
